﻿using FarPoint.Web.Spread;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ControlExplorer.samples.UnboundMode
{
  public partial class Overview : SpreadDemoPage
  {
    Border border1 = new Border();
    StyleInfo style1 = new StyleInfo();

    protected void Page_Load1(object sender, System.EventArgs e)
    {
      if (!Page.IsPostBack)
      {
        PopulateSpread();
        InitConfirmSpread();
        this.FpSpread1.UseClipboard = false;
      }
    }


    public void InitConfirmSpread()
    {
      //Set the paging size
      FpSpread2.Sheets[0].PageSize = 12;

      FarPoint.Web.Spread.Model.ISheetDataModel model;
      model = new FarPoint.Web.Spread.Model.DefaultSheetDataModel(12, 2);

      //Add text
      model.SetValue(0, 0, "姓:");
      model.SetValue(1, 0, "名:");
      model.SetValue(2, 0, "公司:");
      model.SetValue(3, 0, "地址:");
      model.SetValue(4, 0, "城市:");
      model.SetValue(5, 0, "州:");
      model.SetValue(6, 0, "邮编:");
      model.SetValue(7, 0, "电话:");
      model.SetValue(8, 0, "礼物?:");
      model.SetValue(9, 0, "货运途径:");
      model.SetValue(10, 0, "服务:");
      model.SetValue(11, 0, "付款方式:");

      //Apply data to Spread
      FpSpread2.Sheets[0].DataModel = model;

      //Hide the command bar
      FpSpread2.CommandBar.Visible = false;

      //Set header text
      FpSpread2.Sheets[0].ColumnHeaderDataModel.SetValue(0, 0, "字段");
      FpSpread2.Sheets[0].ColumnHeaderDataModel.SetValue(0, 1, "值");

      FpSpread2.Sheets[0].RowHeader.Visible = false;  //Hide row headers

      //Set up columns
      FpSpread2.Sheets[0].Columns[0].Font.Name = "Verdana";
      FpSpread2.Sheets[0].Columns[0].Font.Size = FontUnit.XSmall;
      FpSpread2.Sheets[0].Columns[0].Font.Italic = true;
      FpSpread2.Sheets[0].Columns[0].HorizontalAlign = HorizontalAlign.Right;
      FpSpread2.Sheets[0].Columns[0].BackColor = Color.Linen;
      FpSpread2.Sheets[0].Columns[0].Locked = true;   //Lock to prevent editing

      FpSpread2.Sheets[0].Columns[1].Font.Name = "Verdana";
      FpSpread2.Sheets[0].Columns[1].Font.Size = FontUnit.XSmall;
      FpSpread2.Sheets[0].Columns[1].Locked = true;   //Lock to prevent editing

      //Turn off border for the header
      FpSpread2.Sheets[0].ColumnHeader.DefaultStyle.Border.BorderStyle = BorderStyle.None;

    }

    public void AddToConfirmation(int sourcecol, int destrow, FarPoint.Web.Spread.SpreadCommandEventArgs e, FarPoint.Web.Spread.Model.ISheetDataModel model)
    //Add the edited data to the data model
    {
      if (!object.ReferenceEquals(e.EditValues[sourcecol], FarPoint.Web.Spread.FpSpread.Unchanged))
        model.SetValue(destrow, 1, e.EditValues[sourcecol]);
    }
  }
}